package cn.bytemecc.bloomFilter.config;

import cn.bytemecc.bloomFilter.bitmap.DefaultBitmap;

import cn.bytemecc.bloomFilter.cache.SimpleCaffeine;
import cn.bytemecc.bloomFilter.service.judge.IBloomFilterService;
import cn.bytemecc.bloomFilter.service.judge.impl.BloomFilterServiceImpl;
import cn.bytemecc.bloomFilter.service.save.ISaveCacheService;
import cn.bytemecc.bloomFilter.service.save.impl.SaveCacheServiceImpl;
import cn.bytemecc.bloomFilter.strategy.IHashGenerator;
import cn.bytemecc.bloomFilter.strategy.hashs.SimpleHash;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @description: TODO
 * @author: Liang Zi cao
 * @DATE: 2023/7/16
 * Talk is cheap. Show me the code
 **/
@Configuration

public class BloomFilterAutoConfig {

    @Bean
    public Cache<String, DefaultBitmap> caffeine(){
        return Caffeine.newBuilder()
                .expireAfterWrite(10, TimeUnit.MINUTES)
                .maximumSize(10_000)
                .build();
    }

    @Bean
    public IHashGenerator hashGenerator(){
        return new SimpleHash();
    }
    @Bean
    public SimpleCaffeine simpleCaffeine(Cache cache){
        return new SimpleCaffeine(cache);
    }
    @Bean
    public ISaveCacheService saveCacheService(IHashGenerator hashGenerator,SimpleCaffeine simpleCaffeine){
        return new SaveCacheServiceImpl(hashGenerator,simpleCaffeine);
    }
    @Bean
    public IBloomFilterService bloomFilterService(IHashGenerator hashGenerator,SimpleCaffeine simpleCaffeine){
        return new BloomFilterServiceImpl(hashGenerator,simpleCaffeine);
    }


}
